import java.util.Collections

import com.alibaba.fastjson.JSON
import com.google.gson.{JsonArray, JsonElement, JsonParser}
import org.apache.http.HttpHost
import org.apache.http.util.EntityUtils
import org.elasticsearch.client.RestClient

import scala.collection.immutable.HashMap

/**
  * description:es测试
  **/
object ES2 {

  def main(args: Array[String]): Unit = {

    import com.alibaba.fastjson.JSON
    import org.apache.http.util.EntityUtils
    import org.apache.http.HttpHost
    import org.elasticsearch.client.RestClient


    val ss = "a"
    val restClient = RestClient.builder(new HttpHost("127.0.0.1", 9200, "http")).build()
    val response = restClient.performRequest("post", s"/2019-04-11/ba_diy_risk_relation_article/_search?q=uuid:${ss}")
    val requestLine = response.getRequestLine()
    val host = response.getHost()
    val statusCode = response.getStatusLine().getStatusCode()
    val headers = response.getHeaders()
    val responseBody = EntityUtils.toString(response.getEntity)

    //alibaba
    val jSONObject = JSON.parseObject(responseBody)
//    println(jSONObject)
//    val jSONArray = jSONObject.getJSONArray("hits")
//    println(jSONArray)
    //goole
    val resultData = new JsonParser().parse(responseBody).getAsJsonObject
    val hits = resultData.getAsJsonObject("hits")
    val hitsArr: JsonArray = hits.getAsJsonArray("hits")




    //    val element: JsonElement = hitsArr.get(0)
    //    val eleObj = element.getAsJsonObject
    //    println(eleObj)
    //    println(element)


    //    println(resultData)
    //    println(hits)
        println(hitsArr)
    println(hitsArr.size())

    //    println("[]".equals(string))


    //        println(responseBody)
    //        println(requestLine)
    //        println(data)
    restClient.close();


  }

}
